<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="梅子">
    <title></title>
<style>
     body{
         margin: 0;
     }
     main{
         width: 600px;
         height: 600px;
         margin: 0 auto;
         display: flex;
         flex-wrap: wrap;
         border: 3px solid #999;
     }
     main img{
         width: 190px;
         height: 190px;
         opacity: 0.3;

     }
</style>
</head>
<body>
     <main>
        <div><img src="1.jpg" alt=""></div>
        <div><img src="2.jpg" alt=""></div>
        <div><img src="3.jpg" alt=""></div>
        <div><img src="4.jpg" alt=""></div>
        <div><img src="5.jpg" alt=""></div>
        <div><img src="6.jpg" alt=""></div>
        <div><img src="7.jpg" alt=""></div>
        <div><img src="8.jpg" alt=""></div>
        <div><img src="9.jpg" alt=""></div>
     </main>
</body>
</html>
<script>
    var imgs=document.querySelectorAll('div img');
     for(var i=0;i<imgs.length;i++){
         imgs[i].index=i;
         imgs[i].onmouseover=function(ev){
            imgs[this.index].style.opacity='1';
         }
         imgs[i].onmouseout=function(ev){
            imgs[this.index].style.opacity='0.3';
         }
     }
</script>